package emby.expr;

import java.util.ArrayList;

import emby.EmbyRuntime;
import emby.lang.EmbyList;
import emby.lang.Scope;
import emby.writer.IEmbyCodifier;

/**
 * A list literal expression
 * @author Justin
 *
 */
public class ListExpression extends Expression{

	private static final long serialVersionUID = 5953256992466433240L;
	Expression[] elements;

	/**
	 * Constructs a list literal from the given expressions. When this list literal is evalutated,
	 * the expressions will be evaluated and their return results will be incorporated into the list.
	 * @param elements
	 */
	public ListExpression(Expression... elements){
		this.elements = elements;
	}
	@Override
	public Object eval(Scope s) {
		if(EmbyRuntime.echo){
			emby.util.Print.println("Evaluating list expression... ");
		}
		ArrayList<Object> evaled = new ArrayList<Object>(elements.length);
		for(Expression e: elements){
			evaled.add( e.eval(s));
		}
		return new EmbyList(evaled);
	}

	public void codify(IEmbyCodifier ec){
		ec.list(elements);
	}
}
